<!-- 个人中心 -->
<template>
	<view class="container">
		<view class="apply-box">
			<view class="apply-item" >
				<view style="flex: 1;"  class="title">真实姓名</view>
				<view style="flex: 1;text-align: right;"   class="name">
					<input  v-model="real_name" />
				</view>
			</view>
			<view class="apply-item"  style="margin-top: 30rpx;">
				<view style="flex: 1;" class="title">手机号</view>
				<view   style="flex: 1;text-align: right;" class="name">
					<input  v-model="tel" />
				</view>
			</view>
			<view  class="sfz">身份证正面</view>
			<!-- <view class="xiangji"></view> -->
			
			<!-- <u-upload width="150" :before-upload="beforeUpload" height="150" ref="uUpload"
				@on-uploaded="onUploaded" @on-remove="onRemove" :action="uploadurl" :header="header"
				:form-data="formdata" :index="index" :max-count="9"></u-upload>
			 -->
            <u-upload
              :fileList="fileList"
            	:action="uploadurl"
              @on-uploaded="afterRead"
              @on-remove="deletePic"
              uploadIcon="photo-fill" 
			  :header="header"
			  :form-data="formdata"
              uploadText=""
              multiple :maxCount="10"></u-upload>
		</view>
		<view class="btn" @click="submit">提交</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				fileList:[],
				real_name:'',
				tel:""
			};
		},
computed: {
			header() {
				return {
					token: this.vuex_token || '',
					uid: this.vuex_user.id || 0
				};
			},
			formdata() {
				let multipart = (this.vuex_config.config && this.vuex_config.config.upload.multipart) || '';
				let isObj = this.$u.test.object(multipart);
				if (isObj) {
					return this.vuex_config.config.upload.multipart;
				}
				return {};
			},
			uploadurl() {
				if (!this.vuex_config.upload) {
					return '';
				}
				return this.vuex_config.upload.uploadurl;
			}
		},
		methods: {
			onUploaded(e, name) {
				console.log(e, name);
				this.form['images__' + name] = e
					.map(item => {
						return item.response.data.url;
					})
					.join(',');
			},
			onRemove(index, lists, name) {
				this.form['images__' + name] = lists
					.map(item => {
						return item.response.data.url;
					})
					.join(',');
			},
            // 删除图片
            deletePic(index) {
            	console.log("deletePic",index)
            	this.fileList.splice(index, 1);
            	console.log(this.fileList);
            },
            // 新增图片
            async afterRead(event) {
            	console.log("afterRead",event)
            	// 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
            	this.fileList2 = [];
            	event.forEach(item => {
            		console.log(item)
            		if(item.response!=null){
            			this.fileList.push(item.response.data.fullurl);
            		}	
            	});
            	console.log(this.fileList);
            },
            uploadFilePromise(url) {
            	return new Promise((resolve, reject) => {
            		let a = uni.uploadFile({
            			url: 'http://192.168.2.21:7001/upload', // 仅为示例，非真实的接口地址
            			filePath: url,
            			name: 'file',
            			formData: {
            				user: 'test'
            			},
            			success: (res) => {
            				setTimeout(() => {
            					resolve(res.data.data)
            				}, 1000)
            			}
            		});
            	})
            },
		submit(){
			let that=this
			that.$api.teamApply({
				real_name:that.real_name,
				tel:that.tel,
				img:that.fileList.toString()
			}).then(res => {
				console.log('res', res)
				if(res.code ==1){
					uni.showToast({
						title: '保存成功,请等待审核',
						icon:'none'
					});
					setTimeout(()=>{
						uni.navigateTo({
							url:'/pages/distribution/center'
						})
					},1000)
					
				
				}
				
			});
		}
		}
	};
</script>

<style lang="scss" scoped>
	* {
		box-sizing: border-box;
		margin: 0;
		padding: 0;
	}
	.container{
		background: #F5F5F5;
		height: 100vh;
		overflow: hidden;
	}
	.apply-box{
		height: 444rpx;
		background: #FFFFFF;
		border-radius: 28px;
		margin:30rpx;
		padding: 30rpx;
	}
	.title{
		font-size: 28rpx;
		font-family: Source Han Sans CN;
		font-weight: 400;
		color: #333333;
		line-height: 29rpx;
		height: 54rpx;
	}
	.name{
		font-size: 28rpx;
		font-family: Source Han Sans CN;
		font-weight: 400;
		color: #999999;
		line-height: 29rpx;
		height: 54rpx;
	}
	.apply-item{
		display: flex;
		justify-content: space-between;
		border-bottom: 1px solid #F2F2F2;
	}
	.sfz{
		margin-top: 30rpx;
		font-size: 28rpx;
		font-family: Source Han Sans CN;
		font-weight: 400;
		color: #333333;
		line-height: 29rpx;
	}
	.xiangji{
		background-size: 100% 100%;
		width: 240rpx;
		height: 144rpx;
		background-image: url('/static/image/fenxiao28.png');
		margin-top: 30rpx;
	}
	.btn{
		width: 100%;
		height: 98rpx;
		background: #DE2415;
		font-size: 32rpx;
		font-family: Source Han Sans CN;
		font-weight: 500;
		color: #FFFFFF;
		    position: absolute;
		    bottom: 0;
			display: flex;
		align-items: center;
		justify-content: center;
		}
</style>
